package chapter1.service;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import chapter1.models.Customer;
import chapter1.utils.DButil;

public class CustomerService {
	private static final Logger LOGGER=LoggerFactory.getLogger(CustomerService.class);
	Connection conn=DButil.getConnection();
	
	public List<Customer> getCustomers(Map<String,Object> condition){
		List<Customer> customers=new ArrayList<Customer>();
		try {
			String sql="SELECT * FROM CUSTOMER";
			PreparedStatement ps= conn.prepareStatement(sql);
			ResultSet rs=ps.executeQuery();
			while(rs.next()){
				Customer customer=new Customer();
				customer.setId(rs.getInt("id"));
				customer.setName(rs.getString("name"));
				customer.setContact(rs.getString("contact"));
				customer.setTelephone(rs.getString("telephone"));
				customer.setEmail(rs.getString("email"));
				customer.setRemark(rs.getString("remark"));
				customers.add(customer);
			}
			
		} catch (Exception e) {
			LOGGER.error("getCustomers fails", e);
		}
		return customers;
	};
	
	public Customer getCustomer(Map<String,Object> condition){
		//TODO
		return null;
	}
	
	public Boolean createCustomer(Map<String,Object> condition){
		//TODO
		return null;
	}
	
	public Boolean updateCustomer(Map<String,Object> condition){
		//TODO
		return null;
	}
	
	public Boolean deleteCustomer(Map<String,Object> condition){
		//TODO
		return null;
	}
	

}
